package com.yenlien.traceyun.control.dao;


import com.yenlien.traceyun.control.entity.Message;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by LiuSha on 2020/6/10.
 */
public interface MessageDao extends BaseJpaDao<Message> {
    Message findById(String id);

    @Transactional
    @Modifying
    @Query("update Message m set m.state=2 where m.pid=?1")
        //已经读取
    Integer updateState(String id);


    @Transactional
    @Modifying
    @Query(value = "delete from t_message where pid=?1", nativeQuery = true)
    Integer deleteByPid(String pid);

    @Query(value = "select id,company_id,createtime,content,next,send_user,send_user_id,state,title,type,user_id,app_name,pid,company_name from t_message where pid=?1", nativeQuery = true)
    List<Message> findByPid(String pid);


    @Transactional
    @Modifying
    @Query("update Message m set m.state=1 where m.pid=?1")
        //1，已发送
    Integer updateAllStatus(String pid);
}
